package com.zjk.toolkit.dynamic.thread.pool.sdk.trigger.job;

import com.alibaba.fastjson.JSON;
import com.zjk.toolkit.dynamic.thread.pool.sdk.domain.IDyThreadPoolService;
import com.zjk.toolkit.dynamic.thread.pool.sdk.domain.entity.ThreadPoolEntity;
import com.zjk.toolkit.dynamic.thread.pool.sdk.registry.IRegistry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
public class ThreadPoolReportJob {

    private final IRegistry registry;
    private final IDyThreadPoolService dyThreadPoolService;

    @Scheduled(cron = "0/20 * * * * ?")
    public void report() {
        List<ThreadPoolEntity> threadPoolEntityList = dyThreadPoolService.queryThreadPoolList();
        registry.reportThreadPool(threadPoolEntityList);
        log.info("动态线程池，上报线程池信息：{}", JSON.toJSONString(threadPoolEntityList));

        for (ThreadPoolEntity threadPoolEntity : threadPoolEntityList) {
            registry.reportThreadPoolConfigParamter(threadPoolEntity);
            log.info("动态线程池，上报线程池配置参数：{}", JSON.toJSONString(threadPoolEntity));
        }
    }

}
